package cn.edu.scau.nursingcenter.common;

import javax.servlet.http.HttpServletResponse;

import org.springframework.boot.web.servlet.error.ErrorController;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
/**
 * http状态异常控制器HttpStatusExceptionController：根据状态码，返回对应页面
 * @author feng
 *
 */
@Controller
public class HttpStatusExceptionController implements ErrorController{

	private static final String ERROR_PATH="/error";
	
	@Override
	public String getErrorPath() {
		
		return ERROR_PATH;
	}
	
	@GetMapping(value = ERROR_PATH)
	public String httpStatusHandler(HttpServletResponse response) {
		//code=100+/200+/300+/400+/500+/...
		int code = response.getStatus();
		if(code >= 100 && code < 200) {
			code = 100;
		}else if(code >= 200 && code < 300) {
			code = 200;
		}else if(code >= 300 && code < 400) {
			code = 300;
		}else if(code >= 400 && code < 500) {
			code = 404;
		}else if(code >= 500 && code < 600) {
			code = 500;
		}
		return "/error/"+code;
	}

}
